home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / debug.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  6KB  |  343 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9. #ifndef EXPORT
  10. #ifdef gargar
  11. #include "hdr.h"
  12. #include "ada.h"
  13. #include "adalexp.h"
  14. #include "reducep.h"
  15. #include "pspansp.h"
  16.  
  17. /*
  18.  *        DEBUGGING PROCEDURES (for use with dbx)
  19.  */
  20.  
  21. char *zkind_str(struct ast *);
  22. int zastcount(struct ast *);
  23.  
  24. void zpdeadnode(struct ast *node)                            /*;zpdeadnode*/
  25. {
  26.     printf("Node 0x%x %d, Kind %d %s\n",node,node,
  27.         node->kind,zkind_str(node));
  28.     printf("link: 0x%x %d\n",((struct tmpnode *)node)->link,
  29.         ((struct tmpnode *)node)->link);
  30. }
  31.  
  32. void zpnod_p(struct ast *node)                                /*;zpnod*/
  33. {
  34.     short i,n;
  35.     struct two_pool *listptr;
  36.  
  37.     if (node == NULL) {
  38.         printf("node is NULL\n");
  39.         return;
  40.     }
  41.     printf("Node 0x%x %d, Kind %d %s\n",node,node,
  42.         node->kind,zkind_str(node));
  43.     if (isast_node[node->kind]) {
  44.         n = zastcount(node);
  45.         printf("astcount %d     ",n);
  46.         for (i=0; i<n; i++)
  47.             printf("0x%x ",node->links.subast[i]);
  48.         printf("\n");
  49.     }
  50.     else if (islist_node[node->kind]) {
  51.         printf("list: ");
  52.         if (node->links.list != NULL) {
  53.             listptr = node->links.list;
  54.             do {
  55.                 listptr = listptr->link;
  56.                 printf("0x%x ",listptr->val.node);
  57.             } while (listptr != node->links.list);
  58.             printf("\n");
  59.         }
  60.     }
  61.     else if (node->kind == AS_SIMPLE_NAME) {
  62.         printf("val     %s\n",namelist(node->links.val));
  63.     }
  64.     if (is_terminal_node_p(node->kind) || node == OPT_NODE)
  65.         printf("span line: %d, span col: %d \n",
  66.             node->span.line,node->span.col);
  67. #ifdef TODO
  68.     -- else retrieve and print spans info.
  69. #endif
  70.         return;
  71. }
  72.  
  73. int zastcount(struct ast *node)                            /*;zastcount*/
  74. {
  75.     short i;
  76.  
  77.     i = 1;
  78.     while( i < MAX_AST ) {
  79.         if (node->links.subast[i] == NULL) return(i);
  80.         i++;
  81.     }
  82.     return(MAX_AST);
  83. }
  84.  
  85. void zpnlist(struct two_pool *listptr)                    /*;zpnlist*/
  86. {
  87.     /* dump list of pointers (to nodes) */
  88.     struct two_pool *bottom;
  89.     if (listptr == NULL) {
  90.         printf("null list\n");
  91.         return;
  92.     }
  93.     else {
  94.         bottom = listptr;
  95.         do {
  96.             listptr = listptr->link;
  97.             printf("0x%x ",listptr->val.node);
  98.         } while (listptr != bottom);
  99.     }
  100. }
  101.  
  102. /* Getlabels: Return the list of labels corresponding to a given node. If
  103.    The map is not defined for a node, NULL is returned. */
  104.  
  105. /* this function is defined as dump_labels in labels.c (nodestolabelstable) 
  106. zplabs(node)
  107. struct ast *node;
  108. {
  109.     struct labelsmap *tmp;
  110.     
  111.     for (tmp = nodetolabelstable[labelshash(node)]; tmp != NULL && 
  112.     tmp->node != node; tmp = tmp->link);
  113.     zpnlist(tmp->list);
  114. }
  115. */
  116.  
  117. void zprsstack(struct prsstack *p)                            /*;zprsstack*/
  118. {
  119.     /* dump contents (addresses) of parse stack */
  120.     while (p != NULL) {
  121.         printf("0x%x ",p);
  122.         p = p->prev;
  123.     }
  124.     printf("\n");
  125.  
  126. }
  127.  
  128. void zprssym(struct prsstack *p)                            /*;zprssym*/
  129. {
  130.     /* dump symbols of parse stack */
  131.     while (p != NULL) {
  132.         printf("%s ",TOKSTR(p->symbol));
  133.         p = p->prev;
  134.     }
  135.     printf("\n");
  136.  
  137. }
  138.  
  139. void zpstastack(struct two_pool *s)                            /*;zpstastack*/
  140. {
  141.     int        count = 0;
  142.     while (s != NULL)
  143.     {
  144.         count++ ;
  145.         printf ("%d %s", s -> val.state,
  146.             ( ((count%10) == 0) ? "\n":",") );
  147.         s = s -> link;
  148.     }
  149.     printf (" ======>size = %d<====== \n",count);
  150. }
  151.  
  152. void zprsnod(struct prsstack *p)                            /*;zprsnod*/
  153. {
  154.     /* dump an entry on the parse stack */
  155.     if (p == NULL)
  156.         printf("null pointer\n");
  157.     else if ISTOKEN(p) {
  158.         struct token *tok = p->ptr.token;
  159.  
  160.         printf("%s ",TOKSTR(p->symbol));
  161.         printf("%s\n",namelist(tok->index));
  162.         printf(" line %d  col %d \n",tok->loc.line, tok->loc.col);
  163.     }
  164.     else { /* ast node (nonterminal) */
  165.         printf("%s ",TOKSTR(p->symbol));
  166.         printf(" ast node: %d\n",p->ptr.ast);
  167.         if (p->ptr.ast != NULL)
  168.             zpnod(p->ptr.ast);
  169.     }
  170. }
  171.  
  172. void zdnstack(struct ast *dead)                            /*;zdnstack*/
  173. {
  174.     /* dump contents of dead node stack */
  175.     printf("Deadnode_Stack ");
  176.     while (dead != NULL) {
  177.         printf("0x%x ",dead);
  178.         dead = ((struct tmpnode *)dead)->link;
  179.     }
  180.     printf("End_of_Stack\n");
  181.  
  182. }
  183.  
  184. /*
  185.  * The text of kind_str that follows is generated by a spitbol program
  186.  */
  187. char *zkind_str(struct ast *node)                            /*;kind_str*/
  188. {
  189.     int as;
  190.  
  191.     static char *as_names[] = {
  192.         "pragma",
  193.         "arg",
  194.         "obj_decl",
  195.         "const_decl",
  196.         "num_decl",
  197.         "type_decl",
  198.         "subtype_decl",
  199.         "subtype_indic",
  200.         "derived_type",
  201.         "range",
  202.         "range_attribute",
  203.         "constraint",
  204.         "enum",
  205.         "int_type",
  206.         "float_type",
  207.         "fixed_type",
  208.         "digits",
  209.         "delta",
  210.         "array_type",
  211.         "box",
  212.         "subtype",
  213.         "record",
  214.         "component_list",
  215.         "field",
  216.         "discr_spec",
  217.         "variant_decl",
  218.         "variant_choices",
  219.         "string",
  220.         "simple_choice",
  221.         "range_choice",
  222.         "choice_unresolved",
  223.         "others_choice",
  224.         "access_type",
  225.         "incomplete_decl",
  226.         "declarations",
  227.         "labels",
  228.         "character_literal",
  229.         "simple_name",
  230.         "call_unresolved",
  231.         "selector",
  232.         "all",
  233.         "attribute",
  234.         "aggregate",
  235.         "parenthesis",
  236.         "choice_list",
  237.         "op",
  238.         "in",
  239.         "notin",
  240.         "un_op",
  241.         "int_literal",
  242.         "real_literal",
  243.         "string_literal",
  244.         "null",
  245.         "name",
  246.         "qualify",
  247.         "new_init",
  248.         "new",
  249.         "statements",
  250.         "statement",
  251.         "null_s",
  252.         "assignment",
  253.         "if",
  254.         "cond_statements",
  255.         "condition",
  256.         "case",
  257.         "case_statements",
  258.         "loop",
  259.         "while",
  260.         "for",
  261.         "forrev",
  262.         "block",
  263.         "exit",
  264.         "return",
  265.         "goto",
  266.         "subprogram_decl",
  267.         "procedure",
  268.         "function",
  269.         "operator",
  270.         "formal",
  271.         "mode",
  272.         "subprogram",
  273.         "call",
  274.         "package_spec",
  275.         "package_body",
  276.         "private_decl",
  277.         "use",
  278.         "rename_obj",
  279.         "rename_ex",
  280.         "rename_pack",
  281.         "rename_sub",
  282.         "task_spec",
  283.         "task_type_spec",
  284.         "task",
  285.         "entry",
  286.         "entry_family",
  287.         "accept",
  288.         "delay",
  289.         "selective_wait",
  290.         "guard",
  291.         "accept_alt",
  292.         "delay_alt",
  293.         "terminate_alt",
  294.         "conditional_entry_call",
  295.         "timed_entry_call",
  296.         "abort",
  297.         "unit",
  298.         "with_use_list",
  299.         "with",
  300.         "subprogram_stub",
  301.         "package_stub",
  302.         "task_stub",
  303.         "separate",
  304.         "exception",
  305.         "except_decl",
  306.         "handler",
  307.         "others",
  308.         "raise",
  309.         "generic_function",
  310.         "generic_procedure",
  311.         "generic_package",
  312.         "generic_formals",
  313.         "generic_obj",
  314.         "generic_type",
  315.         "gen_priv_type",
  316.         "generic_subp",
  317.         "generic",
  318.         "package_instance",
  319.         "function_instance",
  320.         "procedure_instance",
  321.         "instance",
  322.         "length_clause",
  323.         "enum_rep_clause",
  324.         "rec_rep_clause",
  325.         "compon_clause",
  326.         "address_clause",
  327.         "any_op",
  328.         "opt",
  329.         "list",
  330.         "range_expression",
  331.         "arg_assoc_list",
  332.         "private",
  333.         "limited_private",
  334.         "code",
  335.         "line_no",
  336.         "free",
  337.         0    };
  338.     as=node->kind;
  339.     return ( (as < 145) ? as_names[as] : "INVALID");
  340. }
  341. #endif
  342. #endif
  343.